<template>
  <div>
    <router-link
    tag="div"
    to="/"
    class="header-abs"
    v-show="showAbs"><span class="iconfont icon-back">&#xe658;</span></router-link>
    <div
    class="header-fixed"
    v-show="!showAbs"
    :style="opacityStyle">
      <router-link
      tag="div"
      to="/"
      class="iconfont header-back">&#xe658;</router-link>
    景点详情</div>
  </div>
</template>

<script>
  export default {
    name: 'DetailHeader',
    data (){
      return {
        showAbs: true,
        opacityStyle: {
          opacity: 0
        }
      }
    },
    methods: {
        handleScroll (){
          const top = document.documentElement.scrollTop
          // this.showAbs = top > 60 ? false : true
          if (top > 60) {
            let opacity = top / 140
            opacity = opacity > 1 ? 1 :opacity
            this.opacityStyle = {opacity}
            this.showAbs = false
          } else {
            this.showAbs = true
          }
        }
      },
    activated (){
      window.addEventListener('scroll', this.handleScroll)
    },
    deactivated (){
      window.removeEventListener('scroll', this.handleScroll)
    }
  }
</script>

<style lang="stylus" scoped>
  @import '~@S/varibles.styl'
  .header-abs
    position: absolute
    left: .2rem
    top: .1rem
    width: .7rem
    height: .7rem
    line-height: .7rem
    border-radius: .4rem
    background: rgba(0,0,0, .5)
    z-index: 99
    text-align: center
    .icon-back
      font-size: .5rem
      color: #ccc
  .header-fixed
    line-height: $headerHeight
    height: $headerHeight
    background: $bgColor
    text-align: center
    color: #fff
    font-size: .32rem
    position: fixed
    top: 0
    left: 0
    right: 0
    overflow: hidden
    z-index: 99
    .header-back
      width: .64rem
      color: #fff
      font-size: .5rem
      text-align: center
      position: absolute
      top: 0
      left: .2rem
</style>
